package com.acme.bankapp.service.bank.network.command;

import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.client.Client;
import com.acme.bankapp.domain.bank.exception.ClientExistsException;

/**
 * This class implements {@link Command} interface for command to add client
 *
 * @author Alexander Kotov (kotov.alex.22@gmail.com)
 */
public class AddClientCommand implements Command {
    private Bank bank;
    private Client client;

    public AddClientCommand(final Bank bank, final Client client) {
        this.bank = bank;
        this.client = client;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String execute() {
        try {
            bank.addClient(client);
        }
        catch (ClientExistsException e) {
            return e.getMessage();
        }
        return client.toString() + " has been successfully added to the bank";
    }
}
